package cn.dida.controller;

import cn.dida.service.CompanyService;
import cn.dida.service.SalesmanService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping(value = "/weixinqyh")
public class WeixinQyhController extends BaseController {
    private Log logger = LogFactory.getLog(WeixinQyhController.class);
    @Autowired
    private CompanyService companyService;
    @Autowired
    private SalesmanService salesmanService;
/*
    @ResponseBody
    @GetMapping("/department/list")
    public Object upload(HttpServletRequest request, Integer type) throws Exception {
        UserSession userSession = getUserSession(request);
        Company company = companyService.getCompany(userSession.getCompanyId());
        JSONObject preference = JSONObject.parseObject(company.getPreference());
        String corpid = preference.getString("weixin_qyh_corpid");
        String corpsecret = preference.getString("weixin_qyh_corpsecret");

        //获取部门列表
        QyhApiClient qyhApiClient = new QyhApiClient(corpid, corpsecret);
        JSONObject re = qyhApiClient.getDepartmentList(null);
        List<Department> departmentList = JSONObject.parseArray(re.getString("department"), Department.class);

        //组织成树结构
        List<Department> departmentTree = new ArrayList<>();
        for (Department department1 : departmentList) {
            if (department1.getParentId().intValue() == 0) {
                departmentTree.add(department1);
            } else {
                for (Department department2 : departmentList) {
                    if (department1.getParentId().intValue() == department2.getId().intValue()) {
                        department1.setParent(department2);
                        department2.getChildren().add(department1);
                    }
                }
            }
        }

        return new HttpResponseBodyWrapper(departmentTree);
    }

    @ResponseBody
    @PostMapping("/sync/salesman")
    public Object syncSalesman(HttpServletRequest request, Integer departmentId) throws Exception {


        UserSession userSession = getUserSession(request);






        return new HttpResponseBodyWrapper(null);
    }*/
}
